//
// Copyright (c) 2009 All Right Reserved
//
// Stephen Toub
// stoub@microsoft.com
// 2009-01-01
// Contains ...
namespace LargoCommon.Midi
{
using System;
using System.Globalization;
using System.IO;
using System.Text;
using Music;
/// Midi event to stop playing a note.
[Serializable]
public sealed class VoiceNoteOff : VoiceAbstractNote {
#region Fields
/// The category status byte for VoiceNoteOff messages.
private const byte CategoryStatusByte = 0x8;
/// The velocity of the note (0x0 to 0x7F).
private byte velocity;
#endregion
#region Constructors
/// Initializes a new instance of the VoiceNoteOff class.
/// The amount of time before this event.
/// The channel (0x0 through 0xF) for this voice event.
/// The MIDI note to stop sounding (0x0 to 0x7F).
/// The velocity of the note (0x0 to 0x7F).
public VoiceNoteOff(long deltaTime, MidiChannel channel, byte note, byte velocity) :
base(deltaTime, CategoryStatusByte, channel, note) {
this.Velocity = velocity;
}
#endregion
#region Properties
/// Gets The second parameter as sent in the MIDI message.
/// General musical property.
public override byte Parameter2 => this.velocity;
/// Gets or sets the velocity of the note (0x0 to 0x7F).
/// General musical property.
private byte Velocity {
get => this.velocity;
set => this.velocity = (byte)(value > 127 ? 127 : value);
}
#endregion
#region To String
/// Generate a string representation of the event.
/// A string representation of the event.
public override string ToString() {
var sb = new StringBuilder();
sb.Append(base.ToString());
sb.Append("\t");
sb.Append(" v=");
sb.Append(this.Velocity.ToString(CultureInfo.CurrentCulture.NumberFormat)); ////ToString("X2"
return sb.ToString();
}
#endregion
#region Methods
/// Write the event to the output stream.
/// The stream to which the event should be written.
public override void Write(Stream outputStream) {
if (outputStream == null) {
return;
}
//// Write out the base event information
base.Write(outputStream);
//// Write out the data
outputStream.WriteByte(this.velocity);
}
#endregion
}
}